import pygame
import pygame_gui

# 初始化 Pygame
pygame.init()

# 设置窗口大小和标题
window_size = (800, 600)
window_surface = pygame.display.set_mode(window_size)
pygame.display.set_caption('Pygame GUI Example')

f = pygame.font.Font(r"C:\Windows\Fonts\msyh.ttc", 20)
ft = f.render("中文", True, (255, 0, 0))

# 创建 GUI 管理器
manager = pygame_gui.UIManager(window_size, 'theme.json')

# 创建按钮和标签
button = pygame_gui.elements.UIButton(
    relative_rect=pygame.Rect((350, 475), (100, 50)),
    text='点击',
    manager=manager
    #object_id='#chinese_button'
)

label = pygame_gui.elements.UITextBox(
    relative_rect=pygame.Rect((350, 200), (200, 250)),
    html_text='hello, world<br />&nbsp;&nbsp;中文',
    manager=manager
#,
#    wrap_to_height=True
    #object_id='#chinese_label'
)

# 主循环
clock = pygame.time.Clock()
running = True

while running:
    time_delta = clock.tick(60) / 1000.0  # 帧率控制

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

        manager.process_events(event)

    manager.update(time_delta)

    window_surface.fill((0, 0, 0))  # 填充背景色
    window_surface.blit(ft, (0, 0))
    manager.draw_ui(window_surface)

    pygame.display.update()

pygame.quit()
